<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2020/8/4
  Time: 11:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/insert.css">
    <script src="/js/jquery-3.4.1.min.js"></script>
</head>
<body>
<div class="jj">
    <div>
        <div class="content">
            <div class="text">用户名:</div>
            <div class="jk"><input type="text" id="username" /></div>
        </div>
        <div  class="content">
            <div class="text">密码:</div>
            <div class="jk"><input type="text" id="password" /></div>
        </div>
        <div class="content">
            <div class="text">确认密码:</div>
            <div class="jk"><input type="text" id="repassword" /></div>
        </div>
        <div class="content">
            <div class="text">验证码:</div>
            <div class="jk"><input type="text" id="code" /></div>
        </div>
        <div class="content">
            <div class="text">手机号:</div>
            <div class="jk"><input type="text" id="phone" /></div>
        </div>
        <div class="content">
            <div class="text">性别:</div>
            <div class="jk">
                <input type="radio" name="sex" value="保密" checked="checked" />保密
                <input type="radio" name="sex" value="男" />男
                <input type="radio" name="sex" value="女" />女
            </div>
        </div>
        <div class="content">
            <div class="text">生日:</div>
            <div class="jk"><input type="date" id="birthday" /></div>
        </div>
        <div class="content">
            <div class="text" >爱好:</div>
            <div class="jk">
                <input type="checkbox" name="hobby" value="游泳" />游泳
                <input type="checkbox" name="hobby" value="跑步" />跑步
                <input type="checkbox" name="hobby" value="打电动" />打电动
            </div>
        </div>
        <div class="content">
            <div class="text" >自我评价:</div>
            <div class="jk"><textarea id="introduce"></textarea></div>
        </div>
        <div class="content">
            <div class="button"><input class="button" type="button" value="清空" /></div>
            <div class="button"><input class="button" type="button" value="注册" onclick="register()" /></div>
        </div>
    </div>
</div>
</body>
<script>
function register() {
    let data = {
        username:$("#username").val(),
        password:$("#password").val(),
        phone:$("#phone").val(),
        sex:$("input[name='sex']:checked").val(),
        birthday:$("#birthday").val(),
        hobby:hb(),
        introduce:$("#introduce").val(),
    };
    console.log(hb());
    $.ajax({
        data:data,
        // tradition:true,
        dataType:'json',
        url:'/insert',
        type:'post',
        success:function (result) {
        }
    })
}
function hb() {
    let hb=[];
    $("input:checkbox[name='hobby']:checked").each(function () {
        let state = ($(this).prop('checked'));
        if (state){
            hb.push($(this).val());
        }
    });
    hb = hb.join(',');
    return hb;

}
</script>
</html>
